package com.daka.controller;

import com.daka.annotation.Login;
import com.daka.entity.Activity;
import com.daka.entity.User;
import com.daka.enumerate.StatusCode;
import com.daka.service.ActivitySignService;
import com.daka.vo.db.ActivitySignVo;
import com.daka.vo.request.ActivityPageRequestVo;
import com.daka.vo.request.UserPageRequestVo;
import com.daka.vo.response.DataResponseVo;
import com.daka.vo.response.ListDataResponseVo;
import com.daka.vo.response.PageListResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * @author beliveli on 2016/3/31 0031.
 */
@Controller
@RequestMapping("/activitySign")
@Slf4j
public class ActivitySignController {

    @Resource(name = "activitySignService")
    private ActivitySignService activitySignService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/listByUser", consumes = "application/json")
    @Login
    public ListDataResponseVo<ActivitySignVo> listByUser(@Valid @RequestBody User user) {
        List<ActivitySignVo> activitySignVoList = activitySignService.selectByUser(user.getUserId());
        return new ListDataResponseVo<>(StatusCode.SUCCESS.getStatusCode(), StatusCode.SUCCESS.getStatusMessage(), activitySignVoList);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/pageListByUser", consumes = "application/json")
    @Login
    public DataResponseVo<PageListResponse<ActivitySignVo>> pageListByUser(@Valid @RequestBody UserPageRequestVo userPageRequestVo) {
        List<ActivitySignVo> activitySignVoList = activitySignService.selectPageByUser(userPageRequestVo.getUserId(), userPageRequestVo.getUserName(), (userPageRequestVo.getPageIndex() - 1) * 10, 10);
        int count = activitySignService.selectCountByUser(userPageRequestVo.getUserId(), userPageRequestVo.getUserName());
        PageListResponse<ActivitySignVo> page = new PageListResponse<ActivitySignVo>(activitySignVoList, count);
        return new DataResponseVo<>(StatusCode.SUCCESS.getStatusCode(), StatusCode.SUCCESS.getStatusMessage(), page);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/listByActivity", consumes = "application/json")
    @Login
    public ListDataResponseVo<ActivitySignVo> listByActivity(@Valid @RequestBody Activity activity) {
        List<ActivitySignVo> activitySignVoList = activitySignService.selectByActivity(activity.getId());
        return new ListDataResponseVo<>(StatusCode.SUCCESS.getStatusCode(), StatusCode.SUCCESS.getStatusMessage(), activitySignVoList);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/pageListByActivity", consumes = "application/json")
    @Login
    public DataResponseVo<PageListResponse<ActivitySignVo>> pageListByActivity(@Valid @RequestBody ActivityPageRequestVo activityPageRequestVo) {
        List<ActivitySignVo> activitySignVoList = activitySignService.selectPageByActivity(activityPageRequestVo.getActivityId(), activityPageRequestVo.getActivityName(), (activityPageRequestVo.getPageIndex() - 1) * 10, 10);
        int count = activitySignService.selectCountByActivity(activityPageRequestVo.getActivityId(), activityPageRequestVo.getActivityName());
        PageListResponse<ActivitySignVo> page = new PageListResponse<ActivitySignVo>(activitySignVoList, count);
        return new DataResponseVo<>(StatusCode.SUCCESS.getStatusCode(), StatusCode.SUCCESS.getStatusMessage(), page);
    }

}
